import type { Dayjs } from 'dayjs';

import type { PageParam, PageResult } from '@vben/request';

import { requestClient } from '#/api/request';

export namespace SystemBusinessAuditLogApi {
  /** 系统业务审核日志信息 */
  export interface BusinessAuditLog {
    id: string; // 主键ID
    businessId?: string; // 业务主表ID，对应 system_business_main.id
    auditOpinion: string; // 审核意见
    auditorId: number; // 审核人ID
    auditorName: string; // 审核人名称
    auditorUnitId: number; // 审核人单位ID
    auditorUnitName: string; // 审核人单位名称
    auditorDeptId: number; // 审核人部门ID
    auditorDeptName: string; // 审核人部门名称
    auditorAreaCode: number; // 审核人行政区划编码
    operateAction: number; // 操作动作（如：提交审核、审核通过、审核不通过、驳回，撤销）
    operateTime: Dayjs | string; // 操作时间
    naturalYear: string; // 自然年度（yyyy）
    naturalMonth: number; // 自然年月（yyyyMM）
    changeContent: string; // 变动日志
    parentId: number; // 上级审核日志id
  }
}

/** 查询系统业务审核日志分页 */
export function getBusinessAuditLogPage(
  data: PageParam,
  desensitize: boolean,
  encrypt: boolean,
) {
  return requestClient.post<
    PageResult<SystemBusinessAuditLogApi.BusinessAuditLog>
  >('/system/business-audit-log/page', data, { desensitize, encrypt });
}

/** 查询系统业务审核日志List */
export function getBusinessAuditLogList(data: any) {
  return requestClient.post<SystemBusinessAuditLogApi.BusinessAuditLog[]>(
    '/system/business-audit-log/list',
    data,
  );
}

/** 查询系统业务审核日志详情 */
export function getBusinessAuditLog(id: number) {
  return requestClient.get<SystemBusinessAuditLogApi.BusinessAuditLog>(
    `/system/business-audit-log/get?id=${id}`,
  );
}

/** 新增系统业务审核日志 */
export function createBusinessAuditLog(
  data: SystemBusinessAuditLogApi.BusinessAuditLog,
) {
  return requestClient.post('/system/business-audit-log/create', data);
}

/** 修改系统业务审核日志 */
export function updateBusinessAuditLog(
  data: SystemBusinessAuditLogApi.BusinessAuditLog,
) {
  return requestClient.put('/system/business-audit-log/update', data);
}

/** 删除系统业务审核日志 */
export function deleteBusinessAuditLog(id: number) {
  return requestClient.delete(`/system/business-audit-log/delete?id=${id}`);
}

/** 批量删除系统业务审核日志 */
export function deleteBusinessAuditLogList(ids: number[]) {
  return requestClient.delete(
    `/system/business-audit-log/delete-list?ids=${ids.join(',')}`,
  );
}

/** 导出系统业务审核日志 */
export function exportBusinessAuditLog(params: any) {
  return requestClient.download('/system/business-audit-log/export-excel', {
    params,
  });
}
